﻿using System;
using System.ComponentModel;
using System.Text;

namespace ProjectEuler.Problems
{
    [EulerProblem(40, 210)]
    [Description("Finding the nth digit of the fractional part of the irrational number.")]
    internal sealed class Problem040 : EulerProblem
    {
        public override Object Solve()
        {
            var builder = new StringBuilder(1000000);
            var result = 1;
            var i = 1;

            while (builder.Length < 1000000)
            {
                builder.Append(i);

                if ((i == 10) ||
                    (i == 100) ||
                    (i == 1000) ||
                    (i == 10000) ||
                    (i == 100000) ||
                    (i == 1000000))
                {
                    result *= (builder[i - 1] - '0');
                }

                i++;
            }

            return result;
        }
    }
}
